home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / 2m21src.zip / 2M-FDTR.C < prev    next >
C/C++ Source or Header  |  1994-05-31  |  8KB  |  247 lines

  1.  
  2. /*********************************************************************
  3. *                                                                    *
  4. *  2M-FDTR 2.1  -  Cálculo de la tasa de transferencia de disquetes. *
  5. *                       (C) 1994 Ciriaco García de Celis.            *
  6. *                                                                    *
  7. *    Para Borland C++ 2.0 ó superior en modelo de memoria large.     *
  8. *                                                                    *
  9. *********************************************************************/
  10.  
  11.  
  12. #define  SMAX  23*512L   /* máximo soportado: 63 sectores por pista */
  13. #define  RD    2
  14. #define  WR    3
  15.  
  16.  
  17. #include <dos.h>
  18. #include <alloc.h>
  19. #include <math.h>
  20. #include <string.h>
  21.  
  22.  
  23. int        evalua_io(), biosdsk(), HablaSp();
  24. void       ayuda();
  25. unsigned long tiempo();
  26.  
  27. int    sp;                    /* 1-español 0-inglés */
  28.  
  29.  
  30. void main (int argc, char **argv)
  31. {
  32.   unsigned char sector0[512], far *buf;
  33.   unsigned long dir;
  34.   int      unidad, cilindros, sectores, cabezales;
  35.   struct   dfree dsk;
  36.  
  37.   sp=HablaSp();  /* determinar idioma del país */
  38.  
  39.   if ((!strcmp(strupr(argv[1]),"/I")) || (!strcmp(strupr(argv[2]),"/I")))
  40.     sp^=1;  /* parámetro /I */
  41.  
  42.   printf("\n 2M-FDTR 2.1\n");
  43.  
  44.   unidad=(*argv[1] | 0x20)-'a';
  45.  
  46.   if ((argc<2) || ((unidad!=0) && (unidad!=1))) ayuda();
  47.  
  48.   getdfree (unidad+1, &dsk);
  49.  
  50.   if (dsk.df_sclus==65535) {
  51.     if (sp)
  52.         printf("   ■ Error de acceso a la unidad.\n");
  53.       else
  54.         printf("   ■ Error on drive access.\n");
  55.     exit (3);
  56.     }
  57.  
  58.   if ((long) dsk.df_total*dsk.df_sclus>65535L) {
  59.     if (sp)
  60.         printf("   ■ Unidades de más de 32M no soportadas.\n");
  61.       else
  62.         printf("   ■ Drive above 32M can not be tested.\n");
  63.     exit (1);
  64.     }
  65.  
  66.   if ((buf=farmalloc (SMAX << 1))==NULL) {
  67.     if (sp)
  68.         printf("   ■ ¡Memoria insuficiente!.\n");
  69.       else
  70.         printf("   ■ Insufficient memory!.\n");
  71.     exit (2);
  72.     }
  73.  
  74.   dir = ((unsigned long) FP_SEG(buf) <<4) + FP_OFF(buf);
  75.   if ((dir>>16)!=((dir+SMAX)>>16)) buf+=SMAX;  /* por el DMA */
  76.  
  77.   if (biosdsk (2, unidad, 0, 0, 1, 1, sector0)) {
  78.     printf("   ■ Fatal ????.\n");
  79.     exit (4);
  80.     }
  81.  
  82.   sectores=sector0[24]+256*sector0[25]; cabezales=sector0[26];
  83.   cilindros=(sector0[19]+256*sector0[20])/sectores/cabezales;
  84.  
  85.   if (sectores>63) {
  86.     if (sp)
  87.         printf("   ■ ¡No soportados más de 63 sectores por pista!.\n");
  88.       else
  89.         printf("   ■ Not supported more than 63 sectors per track!.\n");
  90.     exit (3);
  91.     }
  92.  
  93.   if (sp) {
  94.       printf(" ■ Determinando tasa de transferencia BIOS a disco.\n");
  95.       printf("   + Rendimiento en lectura:\n");
  96.       }
  97.     else {
  98.       printf(" ■ Computing BIOS floppy data transfer rate.\n");
  99.       printf("   + Read performance:\n");
  100.       }
  101.  
  102.   if (evalua_io (RD, buf, unidad, cilindros, sectores, cabezales)) {
  103.     if (dsk.df_avail < dsk.df_total) {
  104.       if (sp)
  105.           printf("   + Disquete no vacío -> test de escritura omitido.\n");
  106.         else
  107.           printf("   + Diskette not empty -> write test skipped.\n");
  108.       exit (4);
  109.       }
  110.     if (sp)
  111.         printf("   + Rendimiento en escritura:\n");
  112.       else
  113.         printf("   + Write performance:\n");
  114.     evalua_io (WR, buf, unidad, cilindros, sectores, cabezales);
  115.     }
  116. }
  117.  
  118.  
  119. void ayuda()
  120. {
  121.   printf(" (C) 1994 Ciriaco García de Celis.\n");
  122.   if (sp) {
  123.       printf("     ■ Indica la unidad A: o B: para medir su velocidad.\n");
  124.       printf("       - El test se realiza accediendo a través de las funciones BIOS.\n");
  125.       printf("       - El buffer E/S no cruza nunca una frontera de DMA de 64K.\n");
  126.       printf("       - El acceso afecta siempre a pistas completas.\n");
  127.       printf("       - El software residente puede alterar el resultado.\n");
  128.       printf("       - El test de escritura no se realiza si el disquete contiene datos.\n");
  129.       }
  130.     else {
  131.       printf("     ■ Choose drive A: or B: to test it absolute speed.\n");
  132.       printf("       - Test is performed always through BIOS functions.\n");
  133.       printf("       - The I/O buffer never cross a 64K DMA frontier.\n");
  134.       printf("       - Access is done always using the whole track.\n");
  135.       printf("       - The TSR software may alter results.\n");
  136.       printf("       - Write test is not performed if diskette contains data.\n");
  137.       }
  138.   exit (255);
  139. }
  140.  
  141.  
  142. unsigned long tiempo()
  143. {
  144.   unsigned long tm;
  145.  
  146.   asm {
  147.     cli
  148.     mov  al,6
  149.     out  43h,al        /* enclavamiento contador 0 */
  150.     in   al,40h
  151.     mov  ah,al
  152.     in   al,40h
  153.     xchg ah,al
  154.     neg  ax            /* ax = valor del contador 0 del 8254 */
  155.     push ds
  156.     mov  bx,40h
  157.     mov  ds,bx
  158.     mov  bx,ds:[6ch]   /* bx = contador hora BIOS */
  159.     sti
  160.     pop  ds
  161.     mov  word ptr tm,ax
  162.     mov  word ptr tm+2,bx
  163.     }
  164.   return (tm);
  165. }
  166.  
  167.  
  168. int biosdsk (int cmd, int drive, int head, int track, int sector,
  169.              int nsects, void *buffer)
  170. {
  171.   union REGS r; struct SREGS s;
  172.  
  173.   r.h.ah=cmd; r.h.dl=drive; r.h.dh=head; r.h.ch=track; r.h.cl=sector;
  174.   r.h.al=nsects; s.es=FP_SEG(buffer); r.x.bx=FP_OFF(buffer);
  175.  
  176.   int86x (0x13, &r, &r, &s);
  177.   return (r.h.ah);
  178. }
  179.  
  180.  
  181. int evalua_io (operacion, buffer, unidad, cilindros, nsect, cabezales)
  182. int operacion, unidad, cilindros, nsect, cabezales;
  183. unsigned char far *buffer;
  184. {
  185.   int      cilindro, cabezal, fin_io=0, res;
  186.   unsigned long tini, tfin;
  187.   float       bseg;
  188.  
  189.   /* Leer parte del cilindro 1 para colocar el cabezal al inicio. */
  190.   /* Se leen dos sectores alejados para esquivar la caché de 2M y */
  191.   /* forzar un auténtico posicionamiento en este cilindro         */
  192.  
  193.   outportb (0x43, 0x36);  /* asegurar que cnt0 usa byte bajo-alto */
  194.   outportb (0x40, 0); outportb (0x40, 0);
  195.  
  196.   biosdsk (2, unidad, 0, 1, 1, 1, buffer);     /* anular caché 2M */
  197.   biosdsk (2, unidad, 0, 1, nsect-2, 1, buffer);   /* sincronizar */
  198.  
  199.   tini=tiempo(); res=0;
  200.   for (cilindro=1; cilindro<cilindros; cilindro++)
  201.     for (cabezal=0; cabezal<cabezales; cabezal++) {
  202.     if (kbhit()) if (getch()==27) goto aborta_io;
  203.     if (res) {
  204.       if (sp)
  205.           printf("\r     ¡Fallo en el acceso a disco!.\n");
  206.         else
  207.           printf("\r     Failure on disk access!.\n");
  208.       goto aborta_io;
  209.       }
  210.     if (sp)
  211.         printf("\r\r       Cilindro %2d - Cara %d", cilindro, cabezal);
  212.       else
  213.         printf("\r\r       Cylinder %2d - Side %d", cilindro, cabezal);
  214.     res=biosdsk (operacion, unidad, cabezal, cilindro, 1, nsect, buffer);
  215.     }
  216.   tfin=tiempo(); fin_io=1;
  217.  
  218.   bseg=(512L*nsect*(cilindros-1)*cabezales)/((tfin-tini)/1193180.0);
  219.   if (sp)
  220.       printf("\r     %7.2f segundos =%7.2f Kb/seg [%7.0f bits/seg]\n",
  221.     (tfin-tini)/1193180.0, bseg/1024.0, bseg*8);
  222.     else
  223.       printf("\r     %7.2f seconds =%7.2f Kb/sec [%7.0f bits/sec]\n",
  224.     (tfin-tini)/1193180.0, bseg/1024.0, bseg*8);
  225.   aborta_io:
  226.   printf("\r                                              \r");
  227.   return (fin_io);
  228. }
  229.  
  230.  
  231. int HablaSp()        /* devolver 1 si mensajes en castellano */
  232. {
  233.   union REGS r; struct SREGS s;
  234.   char info[64];
  235.   int i, idioma, spl[]={54, 591, 57, 506, 56, 593, 503, 34, 63, 502,
  236.              504, 212, 52, 505, 507, 595, 51, 80, 508, 598, 58, 3, 0};
  237.  
  238.   idioma=0;  /* supuesto el inglés */
  239.  
  240.   if (_osmajor>=3) {
  241.     r.x.ax=0x3800; s.ds=FP_SEG(info); r.x.dx=FP_OFF(info);
  242.     intdosx (&r, &r, &s);
  243.     i=0; while (spl[i++]) if (spl[i-1]==r.x.bx) idioma=1;
  244.     }
  245.   return (idioma);
  246. }
  247.